import { DatePicker } from '/client/lib/datepicker';

const utils = require('markdown-it/lib/common/utils');

// Helper function to replace HH with H for 24 hours format, because H allows also single-digit hours
function adjustedTimeFormat() {
  return moment
    .localeData()
    .longDateFormat('LT')
    .replace(/HH/i, 'H');
}

// Edit received, start, due & end dates
BlazeComponent.extendComponent({
  template() {
    return 'editCardDate';
  },

  onCreated() {
    this.error = new ReactiveVar('');
    this.card = this.data();
    this.date = new ReactiveVar(moment.invalid());
  },

  onRendered() {
    const $picker = this.$('.js-datepicker')
      .datepicker({
        todayHighlight: true,
        todayBtn: 'linked',
        language: TAPi18n.getLanguage(),
      })
      .on(
        'changeDate',
        function(evt) {
          this.find('#date').value = moment(evt.date).format('L');
          this.error.set('');
          this.find('#time').focus();
        }.bind(this),
      );

    if (this.date.get().isValid()) {
      $picker.datepicker('update', this.date.get().toDate());
    }
  },

  showDate() {
    if (this.date.get().isValid()) return this.date.get().format('L');
    return '';
  },
  showTime() {
    if (this.date.get().isValid()) return this.date.get().format('LT');
    return '';
  },
  dateFormat() {
    return moment.localeData().longDateFormat('L');
  },
  timeFormat() {
    return moment.localeData().longDateFormat('LT');
  },

  events() {
    return [
      {
        'keyup .js-date-field'() {
          // parse for localized date format in strict mode
          const dateMoment = moment(this.find('#date').value, 'L', true);
          if (dateMoment.isValid()) {
            this.error.set('');
            this.$('.js-datepicker').datepicker('update', dateMoment.toDate());
          }
        },
        'keyup .js-time-field'() {
          // parse for localized time format in strict mode
          const dateMoment = moment(
            this.find('#time').value,
            adjustedTimeFormat(),
            true,
          );
          if (dateMoment.isValid()) {
            this.error.set('');
          }
        },
        'submit .edit-date'(evt) {
          evt.preventDefault();

          // if no time was given, init with 12:00
          const time =
            evt.target.time.value ||
            moment(new Date().setHours(12, 0, 0)).format('LT');
          const newTime = moment(time, adjustedTimeFormat(), true);
          const newDate = moment(evt.target.date.value, 'L', true);
          const dateString = `${evt.target.date.value} ${time}`;
          const newCompleteDate = moment(
            dateString,
            `L ${adjustedTimeFormat()}`,
            true,
          );
          if (!newTime.isValid()) {
            this.error.set('invalid-time');
            evt.target.time.focus();
          }
          if (!newDate.isValid()) {
            this.error.set('invalid-date');
            evt.target.date.focus();
          }
          if (newCompleteDate.isValid()) {
            this._storeDate(newCompleteDate.toDate());
            Popup.close();
          } else if (!this.error) {
            this.error.set('invalid');
          }
        },
        'click .js-delete-date'(evt) {
          evt.preventDefault();
          this._deleteDate();
          Popup.close();
        },
      },
    ];
  },
});

Template.dateBadge.helpers({
  canModifyCard() {
    return (
      Meteor.user() &&
      Meteor.user().isBoardMember() &&
      !Meteor.user().isCommentOnly() &&
      !Meteor.user().isWorker()
    );
  },
});

// editCardReceivedDatePopup
(class extends DatePicker {
  onCreated() {
    // super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
    const momo = moment();
    super.onCreated(moment().format('YYYY-MM-DD HH:mm'));

    const aaa = this.data();
    this.data().getReceived() &&
      this.date.set(moment(this.data().getReceived()));
  }
  onRendered() {
    super.onRendered();
    if (!this.data().getReceived()) {
      $('#date').val(moment().format('YYYY-MM-DD'));
      $('#timeHH').val(moment().format('HH'));
      $('#timeMM').val(moment().format('mm'));
    }
  }

  _storeDate(date) {
    this.card.setReceived(date);
  }

  _deleteDate() {
    this.card.setReceived(null);
  }
}.register('editCardReceivedDatePopup'));

// editCardStartDatePopup
(class extends DatePicker {
  onCreated() {
    const aaa = this.data();

    super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
    this.data().getStart() && this.date.set(moment(this.data().getStart()));
  }

  onRendered() {
    super.onRendered();
    if (moment.isDate(this.card.getReceived())) {
      this.$('.js-datepicker').datepicker(
        'setStartDate',
        this.card.getReceived(),
      );
    }
    if (!this.data().getStart()) {
      $('#date').val(moment().format('YYYY-MM-DD'));
      $('#timeHH').val(moment().format('HH'));
      $('#timeMM').val(moment().format('MM'));
    }
  }

  _storeDate(date) {
    this.card.setStart(date);
  }

  _deleteDate() {
    this.card.setStart(null);
  }
}.register('editCardStartDatePopup'));

// editCardDueDatePopup
(class extends DatePicker {
  onCreated() {
    super.onCreated('1970-01-01 17:00:00');
    this.data().getDue() && this.date.set(moment(this.data().getDue()));
  }

  onRendered() {
    super.onRendered();
    if (moment.isDate(this.card.getStart())) {
      this.$('.js-datepicker').datepicker('setStartDate', this.card.getStart());
    }
  }

  _storeDate(date) {
    this.card.setDue(date);
  }

  _deleteDate() {
    this.card.setDue(null);
  }
}.register('editCardDueDatePopup'));

// editCardEndDatePopup
(class extends DatePicker {
  onCreated() {
    super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
    this.data().getEnd() && this.date.set(moment(this.data().getEnd()));
  }

  onRendered() {
    super.onRendered();
    if (moment.isDate(this.card.getStart())) {
      this.$('.js-datepicker').datepicker('setStartDate', this.card.getStart());
    }
  }

  _storeDate(date) {
    this.card.setEnd(date);
  }

  _deleteDate() {
    this.card.setEnd(null);
  }
}.register('editCardEndDatePopup'));

// Display received, start, due & end dates
const CardDate = BlazeComponent.extendComponent({
  template() {
    return 'dateBadge';
  },

  onCreated() {
    const self = this;
    self.date = ReactiveVar();
    self.now = ReactiveVar(moment());
    window.setInterval(() => {
      self.now.set(moment());
    }, 60000);
  },

  showDate() {
    // this will start working once mquandalle:moment
    // is updated to at least moment.js 2.10.5
    // until then, the date is displayed in the "L" format
    return this.date.get().calendar(null, {
      sameElse: 'llll',
    });
  },

  showISODate() {
    return this.date.get().toISOString();
  },
});

class CardReceivedDate extends CardDate {
  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().getReceived()));
    });
  }

  classes() {
    let classes = 'received-date ';
    const dueAt = this.data().getDue();
    const endAt = this.data().getEnd();
    const startAt = this.data().getStart();
    const theDate = this.date.get();
    // if dueAt, endAt and startAt exist & are > receivedAt, receivedAt doesn't need to be flagged
    if (
      (startAt && theDate.isAfter(startAt)) ||
      (endAt && theDate.isAfter(endAt)) ||
      (dueAt && theDate.isAfter(dueAt))
    )
      classes += 'long-overdue';
    else classes += 'current';
    return classes;
  }

  showTitle() {
    return `${TAPi18n.__('card-received-on')} ${this.date
      .get()
      .format('LLLL')}`;
  }

  events() {
    return super.events().concat({
      'click .js-edit-date': Popup.open('editCardReceivedDate'),
    });
  }
}
CardReceivedDate.register('cardReceivedDate');

class CardStartDate extends CardDate {
  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().getStart()));
    });
  }

  classes() {
    let classes = 'start-date' + ' ';
    const dueAt = this.data().getDue();
    const endAt = this.data().getEnd();
    const theDate = this.date.get();
    const now = this.now.get();
    // if dueAt or endAt exist & are > startAt, startAt doesn't need to be flagged
    if ((endAt && theDate.isAfter(endAt)) || (dueAt && theDate.isAfter(dueAt)))
      classes += 'long-overdue';
    else if (theDate.isAfter(now)) classes += '';
    else classes += 'current';
    return classes;
  }

  showTitle() {
    return `${TAPi18n.__('card-start-on')} ${this.date.get().format('LLLL')}`;
  }

  events() {
    return super.events().concat({
      'click .js-edit-date': Popup.open('editCardStartDate'),
    });
  }
}
CardStartDate.register('cardStartDate');

class CardDueDate extends CardDate {
  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().getDue()));
    });
  }

  classes() {
    let classes = 'due-date' + ' ';
    const endAt = this.data().getEnd();
    const theDate = this.date.get();
    const now = this.now.get();
    // if the due date is after the end date, green - done early
    if (endAt && theDate.isAfter(endAt)) classes += 'current';
    // if there is an end date, don't need to flag the due date
    else if (endAt) classes += '';
    else if (now.diff(theDate, 'days') >= 2) classes += 'long-overdue';
    else if (now.diff(theDate, 'minute') >= 0) classes += 'due';
    else if (now.diff(theDate, 'days') >= -1) classes += 'almost-due';
    return classes;
  }

  showTitle() {
    return `${TAPi18n.__('card-due-on')} ${this.date.get().format('LLLL')}`;
  }

  events() {
    return super.events().concat({
      'click .js-edit-date': Popup.open('editCardDueDate'),
    });
  }
}
CardDueDate.register('cardDueDate');

class CardEndDate extends CardDate {
  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().getEnd()));
    });
  }

  classes() {
    let classes = 'end-date' + ' ';
    const dueAt = this.data().getDue();
    const theDate = this.date.get();
    if (!dueAt) classes += '';
    else if (theDate.isBefore(dueAt)) classes += 'current';
    else if (theDate.isAfter(dueAt)) classes += 'due';
    return classes;
  }

  showTitle() {
    return `${TAPi18n.__('card-end-on')} ${this.date.get().format('LLLL')}`;
  }

  events() {
    return super.events().concat({
      'click .js-edit-date': Popup.open('editCardEndDate'),
    });
  }
}
CardEndDate.register('cardEndDate');

class CardCustomFieldDate extends CardDate {
  template() {
    return 'dateCustomField';
  }

  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().value));
    });
  }

  classes() {
    return 'customfield-date';
  }

  showTitle() {
    return '';
  }

  events() {
    return [];
  }
}
CardCustomFieldDate.register('cardCustomFieldDate');

(class extends CardReceivedDate {
  showDate() {
    return this.date.get().format('l');
  }
}.register('minicardReceivedDate'));

// BlazeComponent.extendComponent({
//   events(){
//     return [
//       {
//         'mouseenter .minicard'() {
//           const currentBoard = Boards.findOne(Session.get('currentBoard'));
//           if (currentBoard.color == 'leangoo') {
//             console.log(12121);
//             this.style.backgroundColor="#eee";
//           }
//         },
//         'mouseleave .minicard'() {
//           const currentBoard = Boards.findOne(Session.get('currentBoard'));
//           if (currentBoard.color == 'leangoo') {
//             this.style.backgroundColor="#fff";
//           }
//          }
//       }
//     ]
//   }
// })
(class extends CardStartDate {
  onRendered() {
    const currentBoard = Boards.findOne(Session.get('currentBoard'));
    if (currentBoard.color == 'leangoo') {
      //leangoo卡片中内容样式的修改和时间样式的修改
      document.querySelectorAll('.date').forEach(function(ele, index) {
        ele.children[0].style.fontSize = '12px';
        ele.children[0].style.backgroundColor = '#fff';
        // var bgcolor = getComputedStyle(document.querySelector(".card-details-item-start").children[1]).backgroundColor
        // ele.children[0].style.color = '#909399';
        //ele.children[0].style.color = bgcolor;
        ele.children[0].style.fontFamily = 'Helvetica Neue';
      });
      let minicardList = document.querySelectorAll('.minicard');
      //加载后时间样式
      // for(let i=0;i<minicardList.length;i++){
      //   for(let j=0;j<minicardList[i].children.length;j++){
      //     if(minicardList[i].children[j].className==="dates"){
      //       if(minicardList[i].children[j].children[0]){
      //        console.log(minicardList[i].children[j].children[0].children[0].children[0].innerHTML=`<i class="iconfont icon-clock"></i>`);
      //       }
      //     }
      //   }
      // }
      // 鼠标移动到卡片上
      for (let i = 0; i < minicardList.length; i++) {
        minicardList[i].onmouseenter = function() {
          for (let i = 0; i < this.children.length; i++) {
            if (this.children[i].className === 'dates') {
              if (this.children[i].children) {
                for (let j = 0; j < this.children[i].children.length; j++) {
                  this.children[i].children[
                    j
                  ].children[0].style.backgroundColor = '#e6e6e6';
                }
              }
            }
          }
        };
        minicardList[i].onmouseleave = function() {
          for (let i = 0; i < this.children.length; i++) {
            if (this.children[i].className === 'dates') {
              if (this.children[i].children) {
                for (let j = 0; j < this.children[i].children.length; j++) {
                  this.children[i].children[
                    j
                  ].children[0].style.backgroundColor = '#fff';
                }
              }
            }
          }
        };
      }
    }
  }
  showDate() {
    // console.log(this.date.get());
    const currentBoard = Boards.findOne(Session.get('currentBoard'));
    if (currentBoard.color == 'leangoo') {
      // document.querySelector('.card-date.almost-due').style.backgroundColor =
      //   'white';
      // document.querySelector('.card-date.almost-due').style.color = '#edc909';
      let day =
        new Date(this.date.get()['_d']).getFullYear() +
        new Date(this.date.get()['_d']).getMonth() +
        new Date(this.date.get()['_d']).getDate();
      let day1 =
        new Date().getFullYear() + new Date().getMonth() + new Date().getDate();
      let i = day - day1;
      if (day == day1) {
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        // window.onload=function(){
        // document.querySelectorAll(".date").forEach(function(ele,index){
        //   ele.children[0].children[0].innerHTML=`<i class=".iconfont.icon-clock">&nbsp;&nbsp;今天${time}`
        // })
        return '今天' + time.substring(0, time.length - 3);
      } else if (day < day1 && i === -1) {
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '昨天' + time.substring(0, time.length - 3);
      } else if (day > day1 && i === 1) {
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '明天' + time.substring(0, time.length - 3);
      } else {
        return (
          // new Date(this.date.get()['_d']).getFullYear() +
          // '年' +
          new Date(this.date.get()['_d']).getMonth() +
          1 +
          '月' +
          new Date(this.date.get()['_d']).getDate() +
          '日'
          // new Date(this.date.get()['_d'])
          //   .toLocaleDateString()
          //   .split('/')
          //   .join('-')
          // +
          //' ' +
          //new Date(this.date.get()['_d']).toLocaleTimeString().substring(0,new Date(this.date.get()['_d']).toLocaleTimeString().length-3)
        );
      }
      //document.querySelector(".date")[]
    } else {
      return this.date.get().format('l');
    }
  }
}.register('minicardStartDate'));

(class extends CardDueDate {
  onRendered() {
    const currentBoard = Boards.findOne(Session.get('currentBoard'));
    if (currentBoard.color == 'leangoo') {
      document.querySelectorAll('.date').forEach(function(ele, index) {
        ele.children[0].style.fontSize = '12px';
        ele.children[0].style.backgroundColor = '#fff';
        //ele.children[0].style.color = '#909399';
        ele.children[0].style.fontFamily = 'Helvetica Neue';
      });
    }
  }
  showDate() {
    const currentBoard = Boards.findOne(Session.get('currentBoard'));
    if (currentBoard.color == 'leangoo') {
      let day =
        new Date(this.date.get()['_d']).getFullYear() +
        new Date(this.date.get()['_d']).getMonth() +
        new Date(this.date.get()['_d']).getDate();
      let day1 =
        new Date().getFullYear() + new Date().getMonth() + new Date().getDate();
      let i = day - day1;
      if (day == day1) {
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '今天' + time.substring(0, time.length - 3);
      } else if (day > day1 && i === 1) {
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '明天' + time.substring(0, time.length - 3);
      } else if ((day > day1) & (i === 2)) {
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '后天' + time.substring(0, time.length - 3);
      } else {
        return (
          // new Date(this.date.get()['_d'])
          //   .toLocaleDateString()
          //   .split('/')
          //   .join('-') +
          // ' ' +
          // new Date(this.date.get()['_d'])
          //   .toLocaleTimeString()
          //   .substring(
          //     0,
          //     new Date(this.date.get()['_d']).toLocaleTimeString().length - 3);
          // new Date(this.date.get()['_d']).getFullYear() +
          // '年' +
          new Date(this.date.get()['_d']).getMonth() +
          1 +
          '月' +
          new Date(this.date.get()['_d']).getDate() +
          '日'
        );
      }
      // document.querySelectorAll(".js-edit-date")[1].style.fontSize="12px"
      // document.querySelectorAll(".js-edit-date")[1].style.backgroundColor="#909399!important";
      // document.querySelectorAll(".js-edit-date")[1].style.fontFamily="Helvetica Neue"
    } else {
      return this.date.get().format('l');
    }
  }
}.register('minicardDueDate'));

(class extends CardEndDate {
  onRendered() {
    const currentBoard = Boards.findOne(Session.get('currentBoard'));
    if (currentBoard.color == 'leangoo') {
      document.querySelectorAll('.date').forEach(function(ele, index) {
        ele.children[0].style.fontSize = '12px';
        ele.children[0].style.backgroundColor = '#fff';
        //ele.children[0].style.color = '#909399';
        ele.children[0].style.fontFamily = 'Helvetica Neue';
      });
      // this.changeFontColor();
      // console.log(11111);
      // let endDate=this.date.get()._d;
      // console.log(endDate);
      //  let Endtime = endDate.getFullYear()+endDate.getMonth()
      // +endDate.getDate()+endDate.getHours()+endDate.getMinutes()+endDate.getSeconds();
      //  console.log(this.date.get()['_d']);
      //  console.log(this.data().getStart());
      //  console.log(this.data().getDue());
      // if((this.date.get()['_d']>this.data().getStart())&&(this.date.get()['_d']<this.data().getDue())){
      // let minicard_wrappers = document.querySelectorAll(".minicard-wrapper");
      // for(let i= 0;i<minicard_wrappers.length;i++){
      //   if(minicard_wrappers[i].href.indexOf(this.data()._id)){
      //     for(let j=0;j<minicard_wrappers[i].children[0].children.length;j++){
      //       if(minicard_wrappers[i].children[0].children[j].className=="dates"){
      //         //console.log(minicard_wrappers[i].children[0][j].children[2].children[0]);
      //         for(let w=0;w<minicard_wrappers[i].children[0].children[j].children.length;w++){
      //           console.log(111);
      //           minicard_wrappers[i].children[0].children[j].children[w].children[0].children[0].style.color="";
      //         }
      //       }
      //     }
      //   }
      // }
      //   let minicard_wrappers =  document.querySelectorAll(".minicard-wrapper");
      //   for(let i= 0;i<minicard_wrappers.length;i++){
      //     if(minicard_wrappers[i].href.indexOf(this.data()._id)){
      //       for(let j=0;j<minicard_wrappers[i].children[0].children.length;j++){
      //         if(minicard_wrappers[i].children[0].children[j].className=="dates"){
      //           if(minicard_wrappers[i].children[0].children[j].children[2]&&minicard_wrappers[i].children[0].children[j].children[2].className=="date"){
      //             console.log(minicard_wrappers[i].children[0].children[j].children[2].children[0]);
      //           minicard_wrappers[i].children[0].children[j].children[2].children[0].children[0].style.color="orange"
      //           }
      //         }
      //       }
      //     }
      //   }
      // }else{
      //   let minicard_wrappers =  document.querySelectorAll(".minicard-wrapper");
      //   for(let i= 0;i<minicard_wrappers.length;i++){
      //     if(minicard_wrappers[i].href.indexOf(this.data()._id)){
      //       for(let j=0;j<minicard_wrappers[i].children[0].children.length;j++){
      //         if(minicard_wrappers[i].children[0].children[j].className=="dates"){
      //           if(minicard_wrappers[i].children[0].children[j].children[2]&&minicard_wrappers[i].children[0].children[j].children[2].className=="date"){
      //             console.log(minicard_wrappers[i].children[0].children[j].children[2].children[0]);
      //           minicard_wrappers[i].children[0].children[j].children[2].children[0].children[0].style.color="red"
      //           }
      //         }
      //       }
      //     }
      //   }
      // }
    }
  }
  // changeFontColor(){
  //   if((this.date.get()['_d']>this.data().getStart())&&(this.date.get()['_d']<this.data().getDue())){
  //     let minicard_wrappers =  document.querySelectorAll(".minicard-wrapper");
  //     for(let i= 0;i<minicard_wrappers.length;i++){
  //       if(minicard_wrappers[i].href.indexOf(this.data()._id)){
  //        console.log(this.data()._id);
  //         for(let j=0;j<minicard_wrappers[i].children[0].children.length;j++){
  //           if(minicard_wrappers[i].children[0].children[j].className=="dates"){
  //             if(minicard_wrappers[i].children[0].children[j].children[2]&&minicard_wrappers[i].children[0].children[j].children[2].className=="date"){
  //               console.log(minicard_wrappers[i].children[0].children[j].children[2].children[0]);
  //             minicard_wrappers[i].children[0].children[j].children[2].children[0].children[0].style.color="orange"
  //             }
  //           }
  //         }
  //       }
  //     }
  //   }else{
  //     let minicard_wrappers =  document.querySelectorAll(".minicard-wrapper");
  //     for(let i= 0;i<minicard_wrappers.length;i++){
  //       if(minicard_wrappers[i].href.indexOf(this.data()._id)){
  //         for(let j=0;j<minicard_wrappers[i].children[0].children.length;j++){
  //           if(minicard_wrappers[i].children[0].children[j].className=="dates"){
  //             if(minicard_wrappers[i].children[0].children[j].children[2]&&minicard_wrappers[i].children[0].children[j].children[2].className=="date"){
  //               console.log(minicard_wrappers[i].children[0].children[j].children[2].children[0]);
  //             minicard_wrappers[i].children[0].children[j].children[2].children[0].children[0].style.color="red"
  //             }
  //           }
  //         }
  //       }
  //     }
  //   }
  //}
  showDate() {
    const currentBoard = Boards.findOne(Session.get('currentBoard'));
    if (currentBoard.color == 'leangoo') {
      let day =
        new Date(this.date.get()['_d']).getFullYear() +
        new Date(this.date.get()['_d']).getMonth() +
        new Date(this.date.get()['_d']).getDate();
      let day1 =
        new Date().getFullYear() + new Date().getMonth() + new Date().getDate();
      let i = day - day1;
      if (day == day1) {
        // this.changeFontColor();
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '今天' + time.substring(0, time.length - 3);
      } else if (day > day1 && i === 1) {
        // this.changeFontColor();
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '明天' + time.substring(0, time.length - 3);
      } else if ((day > day1) & (i === 2)) {
        // this.changeFontColor();
        let time = new Date(this.date.get()['_d']).toLocaleTimeString();
        return '后天' + time.substring(0, time.length - 3);
      } else {
        // this.changeFontColor();
        return (
          // new Date(this.date.get()['_d'])
          //   .toLocaleDateString()
          //   .split('/')
          //   .join('-') +
          // ' ' +
          // new Date(this.date.get()['_d'])
          //   .toLocaleTimeString()
          //   .substring(
          //     0,
          //     new Date(this.date.get()['_d']).toLocaleTimeString().length - 3)
          // new Date(this.date.get()['_d']).getFullYear() +
          // '年' +
          new Date(this.date.get()['_d']).getMonth() +
          1 +
          '月' +
          new Date(this.date.get()['_d']).getDate() +
          '日'
        );
      }
    } else {
      return this.date.get().format('l');
    }
  }
}.register('minicardEndDate'));

(class extends CardCustomFieldDate {
  showDate() {
    return this.date.get().format('l');
  }
}.register('minicardCustomFieldDate'));

class VoteEndDate extends CardDate {
  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().getVoteEnd()));
    });
  }
  classes() {
    const classes = 'end-date' + ' ';
    return classes;
  }
  showDate() {
    return this.date.get().format('l LT');
  }
  showTitle() {
    return `${TAPi18n.__('card-end-on')} ${this.date.get().format('LLLL')}`;
  }

  events() {
    return super.events().concat({
      'click .js-edit-date': Popup.open('editVoteEndDate'),
    });
  }
}
VoteEndDate.register('voteEndDate');

class PokerEndDate extends CardDate {
  onCreated() {
    super.onCreated();
    const self = this;
    self.autorun(() => {
      self.date.set(moment(self.data().getPokerEnd()));
    });
  }
  classes() {
    const classes = 'end-date' + ' ';
    return classes;
  }
  showDate() {
    return this.date.get().format('l LT');
  }
  showTitle() {
    return `${TAPi18n.__('card-end-on')} ${this.date.get().format('LLLL')}`;
  }

  events() {
    return super.events().concat({
      'click .js-edit-date': Popup.open('editPokerEndDate'),
    });
  }
}
PokerEndDate.register('pokerEndDate');
